package novel.mzx.com.activity;

import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.widget.TextView;

import com.lzy.okgo.OkGo;
import com.lzy.okgo.callback.StringCallback;
import com.lzy.okgo.model.Response;

import java.util.List;

import butterknife.BindView;
import novel.mzx.com.R;
import novel.mzx.com.adapter.LaboratoryAdapter;
import novel.mzx.com.base.BaseActivity;
import novel.mzx.com.bean.LaboratoryBean;
import novel.mzx.com.http.Api;
import novel.mzx.com.http.SpDataUtils;
import novel.mzx.com.utils.JSONUtils;

/**
 * 实验课程页面：
 * */

public class MyClassInfoActivity extends BaseActivity {

    @BindView(R.id.recyclerView)
    RecyclerView recyclerView;
    @BindView(R.id.tv_add)
    TextView tv_add;
    private GridLayoutManager mLinearLayoutManager;
    private LaboratoryAdapter laboratoryAdapter;
    @Override
    protected int getResourceId() {
        return R.layout.activity_my_classinfo;
    }

    // 获取所有组件
    @Override
    protected void initView() {
        super.initView();
        mLinearLayoutManager = new GridLayoutManager(this, 1);
        recyclerView.setLayoutManager(mLinearLayoutManager);

        getDatas();

    }

    // 获取数据库所有课程
    private void getDatas() {
        OkGo.<String>post(Api.mainHost+ Api.listlaboratoryInfoUrl)
                .params("laboratoryClass", SpDataUtils.getClassName())
                .execute(new StringCallback() {
                    @Override
                    public void onSuccess(Response<String> response) {
                        Log.e("我的课程",response.body());
                        LaboratoryBean laboratoryBean = JSONUtils.parserObject(response.body(),LaboratoryBean.class);
                        int code = laboratoryBean.getResultCode();
                        if(code == 200){

                            List<LaboratoryBean.Data> data = laboratoryBean.getData();
                            laboratoryAdapter = new LaboratoryAdapter(MyClassInfoActivity.this,R.layout.list_item_laboratory,data);
                            recyclerView.setAdapter(laboratoryAdapter);
                        }
                    }
                });
    }

}
